﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SLBehaviourSystem
{
    public class BehaviourAgent : MonoBehaviour,IBehaviourAgent
    {
        public bool IsEnabled { get; set; }

        public Dictionary<string, BehaviourComponent> Components
        {
            get
            {
                return components;
            }
        }

        protected Dictionary<string, BehaviourComponent> components = new Dictionary<string, BehaviourComponent>();

        public BehaviourTree Tree {
            get
            {
                return tree;
            }
            set
            {
                tree = value;
                tree.OnBehaviourTreeCompleted += ResetData;
            }
        }
        private BehaviourTree tree;

        public virtual void Init()
        {
            
        }

        public void ResetData()
        {
            foreach (var item in components)
            {
                item.Value.Reset();
            }
        }

        public void SetEnable(bool isEnable)
        {
            IsEnabled = isEnable;
            OnSetEnable();
        }

        protected virtual void OnSetEnable()
        {

        }
    }
}
